<?php

namespace App\Containers\AppSection\Questionnaire\Models;

use App\Containers\AppSection\Type\Models\Type;
use App\Ship\Parents\Models\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * Форма
 *
 * @property int $id Id
 * @property string $legal_form_type Тип правовой формы
 * @property string $question Вопрос
 * @property string $description Описание
 * @property bool $required Обязательное
 * @property int $order Сортировка
 * @property bool $some Несколько
 *
 * @property Type $legal_form Правовая форма
 * @property Field[] $fields Поля
 */
class Form extends Model
{
    public $timestamps = false;
    protected $fillable = [
        'legal_form_type',
        'question',
        'description',
        'required',
        'order',
        'some',
    ];
    protected $attributes = [

    ];
    protected $hidden = [

    ];
    protected $casts = [

    ];
    protected $dates = [
        'created_at',
        'updated_at',
    ];
    /**
     * A resource key to be used in the serialized responses.
     */
    protected string $resourceKey = 'Form';
    protected $table = 'questionnaire_forms';

    /**
     * Поля
     * @return HasMany Fields
     */
    public function fields(): HasMany
    {
        return $this->hasMany(Field::class, 'form_id', 'id')->orderBy("id");
    }

    /**
     * Правовая форма
     * @return BelongsTo Type
     */
    public function legal_form(): BelongsTo
    {
        return $this->belongsTo(Type::class, 'legal_form_type', 'key');
    }
}
